//
// Created by lenovo on 2024/2/9.
//

#ifndef PHYSICS_ENGINE_VECTOR_H
#define PHYSICS_ENGINE_VECTOR_H
#include "import.h"

/*
 * 定义物理意义上的向量
 * 在计算的时候
 * direction将被化为单位向量
*/
class Vector {
public :
    Position direction  ;
    double value ;

    //写getter与setter
    [[nodiscard]] Position getDirection() const{
        return this->direction;
    }
    [[nodiscard]] double getValue() const{
        return this->value;
    }
    void setDirection(Position direction){
        this->direction = normalized(direction);
    }
    void setValue(double value) {
        this->value = value;
    }

    //写参数构造函数与默认构造函数
    Vector(Position direction, double value){
        this->setDirection(direction);
        this->setValue(value);
    }
    Vector(){
        this->setDirection({0,0});
        this->setValue(value);
    }

    //定义运算
    Vector operator* (const double& v) const{
        return {normalized(this->getDirection()) , v * this->getValue()};
    }

    Vector operator+ (const Vector& other) const {
        //模拟三角形法则
        Position p0 , p1 ;
        p0 = this->direction * this->value;
        p1 = other.direction * other.value;

        auto tmp = p0 + p1 ;
        return {tmp , magnitude(tmp)};
    }

    Vector operator- (const Vector& other) const {
        //模拟三角形法则
        Position p0 , p1 ;
        p0 = this->direction * this->value;
        p1 = other.direction * other.value;

        auto tmp = p0 - p1 ;
        return {tmp , magnitude(tmp)};
    }
};


#endif //PHYSICS_ENGINE_VECTOR_H
